package com.jimmy.medical.controller;

import com.jimmy.medical.entity.Message;
import com.jimmy.medical.entity.PhoneCall;
import com.jimmy.medical.entity.UploadFile;
import com.jimmy.medical.model.AjaxResult;
import com.jimmy.medical.model.SignInfo;
import com.jimmy.medical.service.ICheckFlowOrderService;
import com.jimmy.medical.service.ISignFlowOrderService;
import com.jimmy.medical.util.AjaxUtils;
import com.jimmy.medical.util.Func_T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/checkFlow")
public class CheckFlowOrderController {

    @Autowired
    private ISignFlowOrderService signFlowOrderService;
    @Autowired
    private ICheckFlowOrderService checkFlowOrderService;

    /**
     * 确认接单
     *
     * @param userId
     * @param： flowOrderId
     * @return
     */
    @RequestMapping("/affirm")
    @ResponseBody
    public AjaxResult<Long> affirm(final Long flowOrderId, final Long userId) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return checkFlowOrderService.saveAffirmInfo(flowOrderId, userId);
            }
        });
    }

    /**
     * 致电客户
     *
     * @return
     * @param: call
     */
    @RequestMapping("/dialToCustomer")
    @ResponseBody
    public AjaxResult<Long> dialToCustomer(final PhoneCall call) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return checkFlowOrderService.saveAffirmDial(call);
            }
        });
    }

    /**
     * 挂号登记界面
     *
     * @param flowOrderId
     * @return
     */
    @RequestMapping("/goSign")
    @ResponseBody
    public AjaxResult<SignInfo> goSign(final Long flowOrderId) {
        return AjaxUtils.process(new Func_T<SignInfo>() {
            @Override
            public SignInfo invoke() throws Exception {
                return signFlowOrderService.getSignInfo(flowOrderId);
            }
        });
    }

    /**
     * 挂号登记
     *
     * @param info
     * @return
     */
    @RequestMapping("/sign")
    @ResponseBody
    public AjaxResult<Long> sign(final SignInfo info) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return checkFlowOrderService.saveSignInfo(info, 3);
            }
        });
    }

    /**
     * 开检查记录
     *
     * @param flowOrderId
     * @return
     */
    @RequestMapping("/goCheckItem")
    @ResponseBody
    public AjaxResult<List<UploadFile>> goCheckItem(final Long flowOrderId) {
        return AjaxUtils.process(new Func_T<List<UploadFile>>() {
            @Override
            public List<UploadFile> invoke() throws Exception {
                return checkFlowOrderService.getCheckItem(flowOrderId);
            }
        });
    }

    /**
     * 开检查
     *
     * @param flowOrderId
     * @param userId
     * @param photoIds
     * @return
     */
    @RequestMapping("/checkItem")
    @ResponseBody
    public AjaxResult<Long> checkItem(final Long flowOrderId, final Long userId, final String photoIds) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return checkFlowOrderService.saveCheckItem(flowOrderId, userId, photoIds);
            }
        });
    }

    /**
     * 电话通知
     *
     * @param call
     * @return
     */
    @RequestMapping("/noticeToCustomer")
    @ResponseBody
    public AjaxResult<Long> noticeToCustomer(final PhoneCall call) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return checkFlowOrderService.saveNoticeInfo(call);
            }
        });
    }

    /**
     * 短信通知
     *
     * @param message
     * @return
     */
    @RequestMapping("/messageToCustomer")
    @ResponseBody
    public AjaxResult<Long> messageToCustomer(final Message message) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return checkFlowOrderService.saveMessageFlow(message);
            }
        });
    }

    /**
     * 完成开检查
     * @return
     */
    @RequestMapping("/submitCheck")
    @ResponseBody
    public AjaxResult<String> submitCheck(final Long flowOrderId, final  Long userId) {
        return AjaxUtils.process(new Func_T<String>() {
            @Override
            public String invoke() throws Exception {
                checkFlowOrderService.submitCheck(flowOrderId, userId);
                return "200";
            }
        });
    }

    /**
     * 取报告确认接单
     *
     * @param： userId
     * @param： flowOrderId
     * @return
     */
    @RequestMapping("/reportAffirm")
    @ResponseBody
    public AjaxResult<Long> reportAffirm(final Long flowOrderId, final Long userId) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return checkFlowOrderService.saveReportAffirmInfo(flowOrderId, userId);
            }
        });
    }

    /**
     * 取报告记录
     *
     * @param： flowOrderId
     * @return
     */
    @RequestMapping("/goTakeReport")
    @ResponseBody
    public AjaxResult<List<UploadFile>> goTakeReport(final Long flowOrderId) {
        return AjaxUtils.process(new Func_T<List<UploadFile>>() {
            @Override
            public List<UploadFile> invoke() throws Exception {
                return checkFlowOrderService.getTakeReport(flowOrderId);
            }
        });
    }

    /**
     * 取报告
     *
     * @param： userId
     * @param： flowOrderId
     * @param： photoIds
     * @return
     */
    @RequestMapping("/takeReport")
    @ResponseBody
    public AjaxResult<Long> takeReport(final Long flowOrderId, final Long userId, final String photoIds) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return checkFlowOrderService.saveTakeReport(flowOrderId, userId, photoIds);
            }
        });
    }

    /**
     * 电话通知报告已取
     *
     * @param call
     * @return
     */
    @RequestMapping("/reportNoticeToCustomer")
    @ResponseBody
    public AjaxResult<Long> reportNoticeToCustomer(final PhoneCall call) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return checkFlowOrderService.saveReportNoticeInfo(call);
            }
        });
    }

    /**
     * 短信通知
     *
     * @param message
     * @return
     */
    @RequestMapping("/reportMessageToCustomer")
    @ResponseBody
    public AjaxResult<Long> reportMessageToCustomer(final Message message) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return checkFlowOrderService.saveReportMessageFlow(message);
            }
        });
    }

    /**
     * 完成取报告
     * @return
     */
    @RequestMapping("/submitCheckReport")
    @ResponseBody
    public AjaxResult<String> submitCheckReport(final Long flowOrderId, final  Long userId) {
        return AjaxUtils.process(new Func_T<String>() {
            @Override
            public String invoke() throws Exception {
                checkFlowOrderService.submitCheckReport(flowOrderId, userId);
                return "200";
            }
        });
    }
}
